def vcb_set_delivery_mode_auto(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "delivery_mode", "auto")
 
def vcb_set_delivery_mode_preview(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "delivery_mode", "preview")  

def vcb_set_auto_dial_mode_engaging(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "auto_dial_mode", "engaging")

def vcb_set_auto_dial_mode_dial_ahead(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "auto_dial_mode", "dial_ahead")
  
def vcb_set_callback_processed_true(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "callback_processed", "true")   
  
def vcb_set_callback_processed_false(): 
  UCBServer.cfgApp.ChangeOption("UCBServer", "callback_processed", "false")  
  
def remove_cpd_from_ucb_connections():
  if not UCBServer.useCPD:
    ProgrammWarning("No CPD is configured in UCBServer connections!!! Nothing will be removed")
  else:
    servers = UCBServer.cfgApp.GetServers()
    for server in servers:
      if server.type == CfgAppType.CFGSDialer.val:
        UCBServer.cfgApp.DeleteConnectionDBID(server.DBID)

def vcb_busy_asap_treatment_1():
  """Callback ASAP to Busy DN, treatment redial"""
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  CB1 = Customer1.RequestVoiceCallBack(BusyCallBackDN, type = VCBType.ASAP)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.ProcessCallBack()  
    if UCBServer.busyCfgTreatment:
      for i in range(0, UCBServer.busyCfgTreatment.cycleAttempt):
        VCBAgent1.PreviewCallBack()
        VCBAgent1.CallBack()
        VCBAgent1.ProcessCallBack()   
  
def vcb_noanswer_asap_treatment_1():
  """Callback ASAP to NoAnswer DN, treatment redial"""
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  CB1 = Customer1.RequestVoiceCallBack(NoAnswerCallBackDN, type = VCBType.ASAP)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.ProcessCallBack()  
    if UCBServer.noAnswerCfgTreatment:
      for i in range(0, UCBServer.noAnswerCfgTreatment.cycleAttempt):
        VCBAgent1.PreviewCallBack()
        VCBAgent1.CallBack()
        VCBAgent1.ProcessCallBack()
  
def vcb_busy_scheduled_treatment_1():
  """Callback Scheduled to Busy DN, treatment redial"""
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  inMins = 2
  CB1 = Customer1.RequestVoiceCallBack(BusyCallBackDN, type = VCBType.Scheduled, timeToCall = time.time() + inMins*60)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.ProcessCallBack()  
    if UCBServer.busyCfgTreatment:
      for i in range(0, UCBServer.busyCfgTreatment.cycleAttempt):
        VCBAgent1.PreviewCallBack()
        VCBAgent1.CallBack()
        VCBAgent1.ProcessCallBack()  
    
def vcb_noanswer_scheduled_treatment_1():
  """Callback Scheduled to NoAnswer DN, treatment redial"""
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  inMins = 2
  CB1 = Customer1.RequestVoiceCallBack(NoAnswerCallBackDN, type = VCBType.Scheduled, timeToCall = time.time() + inMins*60)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.ProcessCallBack()  
    if UCBServer.noAnswerCfgTreatment:
      for i in range(0, UCBServer.noAnswerCfgTreatment.cycleAttempt):
        VCBAgent1.PreviewCallBack()
        VCBAgent1.CallBack()
        VCBAgent1.ProcessCallBack()

def vcb_busy_asap_cancel_treatments_1():
  """Callback ASAP to Voice DN, callback cancel, treatment redial should be skipped"""
  if UCBServer.delivery_mode != "preview": return
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  CB1 = Customer1.RequestVoiceCallBack(BusyCallBackDN, type = VCBType.ASAP)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.CancelCallBack()
    
def vcb_busy_scheduled_cancel_treatments_1():
  """Callback Scheduled to Busy DN, callback cancel, treatment redial should be skipped"""
  if UCBServer.delivery_mode != "preview": return
  UCBServer.AddTreatments()
  VCBAgent1.SetNotReady()
  Customer1.MakeCall(VCBEntryPoint1)
  inMins = 2
  CB1 = Customer1.RequestVoiceCallBack(BusyCallBackDN, type = VCBType.Scheduled, timeToCall = time.time() + inMins*60)
  Customer1.ReleaseCall()  
  VCBAgent1.SetReady()
  if CB1:
    VCBAgent1.PreviewCallBack()
    VCBAgent1.CallBack()
    VCBAgent1.CancelCallBack()         